package com.luckyframe.project.jmeter.jmeterUser.controller;

import com.luckyframe.common.utils.poi.ExcelUtil;
import com.luckyframe.framework.aspectj.lang.annotation.Log;
import com.luckyframe.framework.aspectj.lang.enums.BusinessType;
import com.luckyframe.framework.web.controller.BaseController;
import com.luckyframe.framework.web.domain.AjaxResult;
import com.luckyframe.framework.web.page.TableDataInfo;
import com.luckyframe.project.jmeter.jmeterUser.domain.JmeterUser;
import com.luckyframe.project.jmeter.jmeterUser.service.IJmeterUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 人员管理 信息操作处理
 * 
 * @author lancelot
 * @date 2020-11-24
 */
@Controller
@RequestMapping("/jmeter/jmeterUser")
public class JmeterUserController extends BaseController
{
    private String prefix = "jmeter/jmeterUser";
	
	@Autowired
	private IJmeterUserService jmeterUserService;
	
	@RequiresPermissions("jmeter:jmeterUser:view")
	@GetMapping()
	public String jmeterUser()
	{
	    return prefix + "/jmeterUser";
	}
	
	/**
	 * 查询人员管理列表
	 */
	@RequiresPermissions("jmeter:jmeterUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(JmeterUser jmeterUser)
	{
		startPage();
        List<JmeterUser> list = jmeterUserService.selectJmeterUserList(jmeterUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出人员管理列表
	 */
	@RequiresPermissions("jmeter:jmeterUser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmeterUser jmeterUser)
    {
    	List<JmeterUser> list = jmeterUserService.selectJmeterUserList(jmeterUser);
        ExcelUtil<JmeterUser> util = new ExcelUtil<JmeterUser>(JmeterUser.class);
        return util.exportExcel(list, "jmeterUser");
    }
	
	/**
	 * 新增人员管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存人员管理
	 */
	@RequiresPermissions("jmeter:jmeterUser:add")
	@Log(title = "人员管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(JmeterUser jmeterUser)
	{
		jmeterUser.setCreateTime(new Date());
		return toAjax(jmeterUserService.insertJmeterUser(jmeterUser));
	}

	/**
	 * 修改人员管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		JmeterUser jmeterUser = jmeterUserService.selectJmeterUserById(id);
		mmap.put("jmeterUser", jmeterUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存人员管理
	 */
	@RequiresPermissions("jmeter:jmeterUser:edit")
	@Log(title = "人员管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(JmeterUser jmeterUser)
	{		
		return toAjax(jmeterUserService.updateJmeterUser(jmeterUser));
	}
	
	/**
	 * 删除人员管理
	 */
	@RequiresPermissions("jmeter:jmeterUser:remove")
	@Log(title = "人员管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jmeterUserService.deleteJmeterUserByIds(ids));
	}
	
}
